<?php

namespace App\Providers;

use App\Models\Article;
use App\Models\Book;
use App\Models\BookCollection;
use App\Models\BookList;
use App\Models\Chapter;
use App\Models\User;
use App\Policies\ArticlePolicy;
use App\Policies\BookCollectionPolicy;
use App\Policies\BookListPolicy;
use App\Policies\BookPolicy;
use App\Policies\ChapterPolicy;
use App\Policies\UserPolicy;
use Carbon\Carbon;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Laravel\Passport\Passport;
use Laravel\Passport\RouteRegistrar;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
        Chapter::class => ChapterPolicy::class,
        User::class => UserPolicy::class,
        Article::class => ArticlePolicy::class,
        Book::class => BookPolicy::class,
        BookCollection::class => BookCollectionPolicy::class,
        BookList::class => BookListPolicy::class
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        Passport::routes();

        // token的有效时间为15天
        Passport::tokensExpireIn(Carbon::now()->addDays(15));

        // 刷新token的有效时间为30天
        Passport::refreshTokensExpireIn(Carbon::now()->addDays(30));
    }
}
